<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="layer.js"></script>
<script src="layui.js"></script>
<link rel="stylesheet" href="css/layui.css" media="all">
<script src="dist/js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
    <form class="layui-form" action="" style="position: relative; left: 380px; top: 100px;">
            <h1 style="position: relative; left: 110px; margin-bottom: 20px;">?~提问</h1>
			<div class="layui-form-item">
				<label class="layui-form-label">标题:</label>
				<div class="layui-input-block">
					<input style="width: 500px;" type="text" name="qTitle" id="qTitle" lay-verify="qTitle" autocomplete="off" placeholder="请输入标题" class="layui-input" required="required">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">内容:</label>
				<div class="layui-input-block">
					<textarea style="width: 500px;" class="span8" name="qContent" id="qContent" placeholder="请输入内容，越详细越好~" lay-verify="qContent" cols="58"
										rows="10"  required="required"></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
		<script type="text/javascript">
			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate;


				//自定义验证规则
				form.verify({
					qTitle: function(value) {
						if(value.length < 1) {
							return '标题不能为空哦！！';
						}
					},
					qContent: function(value) {
						if(value.length < 20) {
							return '内容不能少于20个字符哦！！';
						}
					}
				});
				form.on('submit(demo1)', function(data) {
					$.ajax({
						url : "QuestionTopServlet?op=submitQuestion",
						type : "post",
						data : {
							"qTitle" : $('#qTitle').val(),
							"qContent" : $('#qContent').val(),
							"userId" : ${userTopLogin.userId}
						},
						success : function(data) {
							if (data == "false") {
								layer.msg('提交失败，请重新提交', {
									time : 3000
								});
							} else {
								layer.msg('提交成功   感谢你对我们的大力支持', {
									time : 3000, //3s后自动关闭
									btn : [ '知道了' ]
								}, function() {
									location.href = "index-2.jsp"
									window.parent.location.reload();
								});
								
							}
						}
					});
					return false;
				});

			});
		</script>

</body>
</html>